<?php
/**
 * Email:zhaojunlike@gmail.com
 * Date: 2017/1/15
 * Time: 16:11
 */

require "AliSDK/TopSdk.php";

const APPKEY = "23769930";
const APPSRET = "cc6bb5eb95f88c7306c254cfa9042e17";
//api自定义签名
const SIGNKEY = "5f444879540225c58158f12d23029e98";

function get_status_str($status)
{
    switch (intval($status)) {
        case 1:
            return "充电中";
            break;
        case 2:
            break;
        case 0:
            return "断电了";
            break;
    }
    return "";
}

function ali_send_sms_verify($code, $product, $phone)
{
    $c = new TopClient();
    $c->appkey = APPKEY;
    $c->secretKey = APPSRET;
    $req = new AlibabaAliqinFcSmsNumSendRequest;
    $req->setExtend("123456");
    $req->setSmsType("normal");
    $req->setSmsFreeSignName("报警通知");
    $req->setSmsParam("{\"code\":\"{$code}\",\"product\":\"{$product}\"}");
    $req->setRecNum($phone);
    $req->setSmsTemplateCode("SMS_41650275");
    $resp = $c->execute($req);
    if ($resp->result->err_code == 0) {
        return true;
    } else {
        return false;
    }
}

function ali_send_sms_notice($driver_no, $driver_status, $phone)
{
    $c = new TopClient();
    $c->appkey = APPKEY;
    $c->secretKey = APPSRET;
    $req = new AlibabaAliqinFcSmsNumSendRequest();
    $req->setExtend("123456");
    $req->setSmsType("normal");
    $req->setSmsFreeSignName("电力监控");
    $sendArr = [];
    $sendArr['driver_no'] = $driver_no;
    $sendArr['driver_status'] = $driver_status;
    $sendArr['date']=date("H:i:s");
    $req->setSmsParam(json_encode($sendArr));
    $req->setRecNum($phone);
    $req->setSmsTemplateCode("SMS_41650275");
    $resp = $c->execute($req);
    if ($resp->result->err_code == 0) {
        return true;
    } else {
        return false;
    }
}

function parse_phone($phone_str, $char)
{
    $arr = explode($char, $phone_str);
    return $arr;
}
